﻿using System;
using System.Collections.Generic;
using System.Linq;
using Business.DbConnect;

namespace Business
{
    public class MotorTypeBusiness
    {
        static QLNXeEntities entity = new QLNXeEntities();

        public static List<MotorType> ListMotorTypes()
        {
            try
            {
                return entity.MotorTypes.ToList();
            }
            catch (Exception)
            {
                return new List<MotorType>();
            }
        }

        /// <summary>
        ///
        /// </summary>
        /// <param name="plate"></param>
        /// <returns></returns>
        public static MotorType SelectMotorTypeByPlate(String plate)
        {
            try
            {
                QLNXeEntities entities = new QLNXeEntities();
                var query = from tiket in entities.Tickets
                            where tiket.MotorbikePlate == plate
                            join motor in entities.Motorbikes on tiket.MotorbikePlate equals motor.Plate
                            join motorType in entities.MotorTypes on motor.MotorType equals motorType.Id
                            select motorType;
                return query.First();
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}